﻿function listen(event, elem, func) {
    elem = getElem(elem);
    if (elem.addEventListener) { // W3C DOM
        elem.addEventListener(event,func,false);
    } else if (elem.attachEvent) { // IE DOM
        elem.attachEvent('on'+event, function(){ func(new W3CDOM_Event(elem)) } );
    } else {
        throw 'cannot add event listener';
    }
        // for IE we use a wrapper function that passes in a simplified faux Event object.
    
}
function W3CDOM_Event(currentTarget) {
    this.currentTarget  = currentTarget;
    this.preventDefault = function() { window.event.returnValue = false }
    return this;
}
function getElem(elem) {
    if (document.getElementById) {
        if (typeof elem == "string") {
            elem = document.getElementById(elem);
            if (elem===null) throw 'cannot get element: element does not exist';
        } else if (typeof elem != "object") {
            throw 'cannot get element: invalid datatype';
        }
    } else throw 'cannot get element: unsupported DOM';
    return elem;
}
function addondate(date) {
    return function(e) {
        togglevis('phase','calwrapper','addform');
        document.getElementById('addevstartdate').value = date;
        document.getElementById('addevenddate').value = date;
        e.preventDefault();
        return false;
    };
}
function overlayfunc(num,type) {
    return function(e) { overlay('mousehook'+num, type+num); e.preventDefault() };
}
function closefunc(num,type) {
    return function(e) { overlayclose(type+num) };
}
function datepickerfunc(par1,par2,par3) {
    if(par3 == null) {
      return function(e) { scwShow(scwID(par1),par2) };
    }
}
function togglevisfunc(type,par1,par2,par3,par4,par5,par6) {
    if(par2 == null) {
      return function(e) { togglevis(type,par1); e.preventDefault() };
    } else if(par3 == null) {
      return function(e) { togglevis(type,par1,par2); e.preventDefault(); };
    } else if(par4 == null) {
      return function(e) { togglevis(type,par1,par2,par3); e.preventDefault() };
    } else if(par5 == null) {
      return function(e) { togglevis(type,par1,par2,par3,par4); e.preventDefault() };
    } else if(par6 == null) {
      return function(e) { togglevis(type,par1,par2,par3,par4,par5); e.preventDefault() };
    } else {
      return function(e) { togglevis(type,par1,par2,par3,par4,par5,par6); e.preventDefault() };
    }
}
function addlink(par1,par2,par3) {
      return function(e) { 
        togglevis(par1,par2,par3); 
        document.getElementById('calwrapper').style.height = 'auto';
        e.preventDefault();
      };
}
function showtabfunc(par1,par2,par3,par4) {
    return function(e) { togglevis('on',par1,par2,par3); markactive('addmenu',par4); };
}
function showsearchtabfunc(par1,par2,par3) {
    return function(e) { 
        togglevis('on',par1,par2); 
        markactive('searchmenu',par3);
        if(par1 == 'findtasks') {
          document.getElementById('mode').value = 't';
        } else {
          document.getElementById('mode').value = 'e';
        }
    };
}
function showmenu(type, item1, item2, menuid, id) {
    return function(e) { togglevis(type, item1, item2); markactive(menuid, id); };
}
function showcustomise(type) {
    return function(e) {
    if(type == 'show') {
        document.getElementById('customisepanel').style.display = 'block';
        if(document.getElementById('day') != null) { document.getElementById('day').style.display = 'none'; }
        if(document.getElementById('month') != null) { document.getElementById('month').style.display = 'none'; }
        if(document.getElementById('year') != null) { document.getElementById('year').style.display = 'none'; }
        getcustpanel();
    } else if(type == 'hide') {
        if(document.getElementById('day') != null) { document.getElementById('day').style.display = 'inline'; }
        if(document.getElementById('month') != null) { document.getElementById('month').style.display = 'inline'; }
        if(document.getElementById('year') != null) { document.getElementById('year').style.display = 'inline'; }
        new Effect.Fade('customisepanel', {duration:0.5} );
    }
    };
}
function showcustomiseplain(type) {
    if(type == 'show') {
        document.getElementById('customisepanel').style.display = 'block';
        if(document.getElementById('day') != null) { document.getElementById('day').style.display = 'none'; }
        if(document.getElementById('month') != null) { document.getElementById('month').style.display = 'none'; }
        if(document.getElementById('year') != null) { document.getElementById('year').style.display = 'none'; }
        getcustpanel();
    } else if(type == 'hide') {
        if(document.getElementById('day') != null) { document.getElementById('day').style.display = 'inline'; }
        if(document.getElementById('month') != null) { document.getElementById('month').style.display = 'inline'; }
        if(document.getElementById('year') != null) { document.getElementById('year').style.display = 'inline'; }
        new Effect.Fade('customisepanel', {duration:0.5} );
    }
}
function dopost(buttonname, k1, v1, k2, v2, k3, v3, k4, v4, k5, v5, k6, v6) {
    return function(e) {
    var f = document.createElement('form'); 
    f.style.display = 'none'; 
    document.getElementById(buttonname).parentNode.appendChild(f);
        var h1 = document.createElement('input'); h1.type = 'hidden'; h1.name = k1; h1.value = v1; f.appendChild(h1);
        var h2 = document.createElement('input'); h2.type = 'hidden'; h2.name = k2; h2.value = v2; f.appendChild(h2);
        var h3 = document.createElement('input'); h3.type = 'hidden'; h3.name = k3; h3.value = v3; f.appendChild(h3);
        if(typeof k4 != "undefined") {
          var h4 = document.createElement('input'); h4.type = 'hidden'; h4.name = k4; h4.value = v4; f.appendChild(h4);
        }
        if(typeof k5 != "undefined") {
          var h5 = document.createElement('input'); h5.type = 'hidden'; h5.name = k5; h5.value = v5; f.appendChild(h5);
        }
        if(typeof k6 != "undefined") {
          var h6 = document.createElement('input'); h6.type = 'hidden'; h6.name = k6; h6.value = v6; f.appendChild(h6);
        }
        f.method = 'POST'; 
    f.action = 'index.php'; 
    f.submit();
    return false;
    };
}
function setalldayfunc(id, type) {
    return function(e) { setallday(id, type) };
}
function ongoingfunc(id, type) {
    return function(e) {
      if((document.getElementById(type+'taskongoing') != null) || (document.getElementById(id+'taskongoing') != null)) {
        if(id == 'main') {
          box = document.getElementById(type+'taskdatedue');
          if(document.getElementById(type+'taskongoing').checked) {
            box.disabled = true;
            box.value = '';
          } else if(!document.getElementById(type+'taskongoing').checked) {
            box.disabled = false;
            box.className = 'standard';
            time = new Date();
            box.value = time.getDate() +'/'+(time.getMonth()+1) +'/'+time.getFullYear();
          }
        } else {
          box = document.getElementById(id+'taskdatedue');
          if(document.getElementById(id+'taskongoing').checked) {
            box.disabled = true;
            box.value = '';
          } else if(!document.getElementById(id+'taskongoing').checked) {
            box.disabled = false;
            box.className = 'standard';
            time = new Date();
            box.value = time.getDate() +'/'+(time.getMonth()+1) +'/'+time.getFullYear();
          }
        }
      }
    };
}
function makerequestfunc(act, view, secs, type, divtype) {
    return function(e) { makerequest(act, view, secs, type, divtype) };
}
function doupdatefunc(k1, v1, k2, v2, k3, v3, k4, v4) {
    return function(e) { doupdate(k1, v1, k2, v2, k3, v3, k4, v4) };
}